package com.swt.controller;

import com.swt.common.utils.QiNiuYunUpFileUtils;
import com.swt.common.vo.ResponseVo;
import com.swt.domain.Admin;
import com.swt.domain.Goods;
import com.swt.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description
 * @Author swt
 * @Date 2022/5/17
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    public GoodsService goodsService;
    @PostMapping("/{count}/{size}")
    public ResponseVo getGoods(@PathVariable Integer count,
                               @PathVariable Integer size,
                               @RequestBody(required = false) Goods goods){
        return ResponseVo.SUCCESS(goodsService.pageGoods(count,size,goods));

    }
    @DeleteMapping("/{id}")
    public ResponseVo deleGoods(@PathVariable String id){
        return goodsService.delectGoods(id)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
    @GetMapping("/{id}")
    public ResponseVo selectbyGoodid(@PathVariable String id){
        return ResponseVo.SUCCESS(goodsService.selectbyGoodid(id));
    }
    @PostMapping
    public ResponseVo inserGoods(@RequestBody Goods s){
        return goodsService.inserGoods(s)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
    @PutMapping
    public ResponseVo updategoods(@RequestBody Goods s){
        return goodsService.updateGoods(s)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
    @PostMapping("/upload")
    public ResponseVo upLoadGoodsImg(MultipartFile file){
        System.out.println(file);
        return QiNiuYunUpFileUtils.getUpLoad(file);
    }
}
